#include <iostream>
#include <memory>
#include <string>
#include <list>

using namespace std;


/*
\ brief:  命令抽象接口类型
\ author: 清晨与猫鱼
*/
class Order {
public:
    virtual void execute() = 0;         // 接口函数：执行
};

/*
\ brief:  股票
\ author: 清晨与猫鱼
*/
class Stock {
public:
    void buy() {
        cout << "Stock [ Name: " << name_ << ", Quantity: "
            << quantity_ << " ] bought" << endl;
    }

    void sell() {
        cout << "Stock [ Name: " << name_ << ", Quantity: " 
            << quantity_ << " ] sold" << endl;
    }
private:
    string name_= "ABC";
    int quantity_ = 10;
};

/*
\ brief:   买股票
\ author: 清晨与猫鱼
*/
class BuyStock 
    : public Order {
public:
    explicit BuyStock(Stock* abcStock)
        : abcStock_(abcStock) {
    }

    void execute() {
        abcStock_->buy();
    }

private:
    Stock* abcStock_;
};



/*
\ brief:  出售股票
\ author: 清晨与猫鱼
*/
class SellStock 
    : public Order {
public:
    explicit SellStock(Stock* abcStock) 
        : abcStock_(abcStock){
    }

    void execute() {
        abcStock_->sell();
    }
private:
    Stock* abcStock_;
};


/*
\ brief:   经纪人
\ author: 清晨与猫鱼
*/
class Broker {
public:
    void takeOrder(Order* order) {
        orderList_.emplace_back(order);
    }

    void placeOrders() {
        for (unique_ptr<Order>& order : orderList_) {
            order->execute();
        }
        orderList_.clear();
    }

private:
    list<unique_ptr<Order>> orderList_;     // 命令列表
};